package com.zchat.android.adapters;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zchat.android.service_aidl_beans.User;

/**
 * 联系人列表
 * @author Oliverzhu
 * 2012/6/23
 */
public class RosterAdapter extends BaseAdapter {
	private List<User> userinfos;
	private Context context;

	public RosterAdapter(Context context,List<User> userinfos) {
		this.userinfos = userinfos;
		this.context = context;
	}

	@Override
	public int getCount() {
		return userinfos.size();
	}

	@Override
	public Object getItem(int position) {
		return userinfos.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	private class ViewHolder {
		TextView user;
		TextView status;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		User user = userinfos.get(position);
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			LinearLayout layout = new LinearLayout(context);

			holder.user = new TextView(context);
			holder.status = new TextView(context);
			layout.setOrientation(LinearLayout.HORIZONTAL);
			layout.addView(holder.status);
			layout.addView(holder.user);
			convertView = layout;
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.user.setText(user.getUserName());
		holder.status.setText(user.getStatus());

		return convertView;
	}
}
